#pragma once

#include <QtWidgets/QMainWindow>
#include <json/json.h>
#include <hv/hv.h>
#include "hv/WebSocketClient.h"
#include <QTimer>

enum class cmd {
    INITCON,
    SEND,
    SENDIMG
};
class QLabel;
class QLineEdit;
class QPushButton;
class QTextEdit;
class TWebSocketClient : public QMainWindow
{
    Q_OBJECT

public:
    TWebSocketClient(QWidget *parent = nullptr);
    ~TWebSocketClient();

private slots:
    void onSelectImgButtonReleased();
    void onSendImgButtonReleased();

    

private:
    void initUI();
    void initConnect();
    bool open(const char* url);
    void close();
    int cmdToInt(cmd command);
    std::string parseContent(const std::string& msg);
    std::string imageToString(const QString& filename);

    QLabel* m_pUrlLabel;
    QLineEdit* m_pUrlLineEdit;
    QPushButton* m_pStartButton;
    QPushButton* m_pCloseButton;
    QPushButton* m_pSendButton;
    QTextEdit* m_pTextEdit;
    QTextEdit* m_pDisplayTextEdit;
    QPushButton* m_pSelectImgButton;
    QPushButton* m_pSendImgButton;

    hv::WebSocketClient* client;

    QString selectedImagePath;
    QString selectedImageName;

    //QTimer* timer;
    int executionCount = 0; // 执行计数器
    const int maxExecutions = 500; // 最大执行次数
};
